clear
clear all
cap log close
log using ..\output\logfiles\Table_1_2.smcl, replace

use  ..\temp\trade_data_h6_covars_h1.dta, clear

***** Regressions ************************
******************************************
**********************************************************************************************************************************************************************************************************************
//Prelimn
egen ych4 = group(h4 y c)
egen tag_hs4 = tag(ych4)

bys c y: egen total = total(v)
gen v_share = v/total

gen ln_v = ln(v)
 
loc run = 1
if `run' == 1{
	
//Panel A

reg B1_hs6 commodity_exports, cluster(cy)
sum B1_hs6 if e(sample)==1
loc m = r(mean)
outreg2 using ..\output\Table_1_panelA.tex,  tex(frag) replace label  nocons dec(0) rdec(2) addtext(HS digit product category, 6, Country-product fixed effects, No, Product-year fixed effects, No) addstat(Dependent variable mean, `m') sortvar(commodity_exports compriceindexfixw loggdppc gini_i cce rqe)

reghdfe B1_hs6 commodity_exports , absorb(yh6) cluster(cy)
sum B1_hs6 if e(sample)==1
loc m = r(mean)
outreg2 using ..\output\Table_1_panelA.tex, tex(frag) append label  nocons addtext(HS digit product category, 6, Country-product fixed effects, No, Product-year fixed effects, Yes) addstat(Dependent variable mean, `m')  dec(0) rdec(2) sortvar(commodity_exports compriceindexfixw loggdppc gini_i cce rqe)

reghdfe B1_hs6 commodity_exports , absorb(ch6 yh6) cluster(cy)
sum B1_hs6 if e(sample)==1
loc m = r(mean)
outreg2 using ..\output\Table_1_panelA.tex, tex(frag) append label  nocons addtext(HS digit product category, 6, Country-product fixed effects, Yes, Product-year fixed effects, Yes) addstat(Dependent variable mean, `m')  dec(0) rdec(2) sortvar(commodity_exports compriceindexfixw loggdppc gini_i cce rqe)

reghdfe B1_hs6 commodity_exports loggdppc gini_i cce rqe , absorb(ch6 yh6) cluster(cy) 
sum B1_hs6 if e(sample)==1
loc m = r(mean)
outreg2 using ..\output\Table_1_panelA.tex, tex(frag) append label  nocons addtext(HS digit product category, 6, Country-product fixed effects, Yes, Product-year fixed effects, Yes) addstat(Dependent variable mean, `m')  dec(0) rdec(2)   sortvar(commodity_exports compriceindexfixw loggdppc gini_i cce rqe)

reghdfe B1_hs6 compriceindexfixw, absorb(ch6 yh6) cluster(cy) 
sum B1_hs6 if e(sample)==1
loc m = r(mean)
outreg2 using ..\output\Table_1_panelA.tex, tex(frag) append label  nocons addtext(HS digit product category, 6, Country-product fixed effects, Yes, Product-year fixed effects, Yes) addstat(Dependent variable mean, `m')  dec(0) rdec(2)  sortvar(commodity_exports compriceindexfixw loggdppc gini_i cce rqe)

reghdfe B1_hs6 compriceindexfixw loggdppc gini_i cce rqe, absorb(ch6 yh6) cluster(cy)
sum B1_hs6 if e(sample)==1
loc m = r(mean)
outreg2 using ..\output\Table_1_panelA.tex, tex(frag) append label  nocons addtext(HS digit product category, 6, Country-product fixed effects, Yes, Product-year fixed effects, Yes) addstat(Dependent variable mean, `m')  dec(0) rdec(2)  sortvar(commodity_exports compriceindexfixw loggdppc gini_i cce rqe)

}

********************************************************************************
********************************************************************************
//Panel B Type of good
loc run =1
if `run' == 1{
	
********************************************************************************
********************************************************************************

reghdfe B1_hs6 commodity_exports  if type_of_good=="primary", absorb(ch6 yh6) cluster(cy)
sum B1_hs6 if e(sample)==1
loc m = r(mean)
outreg2 using ..\output\Table_1_panelB.tex, tex(frag) replace label nocons addtext(HS digit product category, 6, Country-product fixed effects, Yes, Product-year fixed effects, Yes) addstat(Dependent variable mean, `m' ) dec(0) rdec(2) ctitle ("Primary")   

reghdfe B1_hs6 commodity_exports  if type_of_good=="capital", absorb(ch6 yh6) cluster(cy)
sum B1_hs6 if e(sample)==1
loc m = r(mean)
outreg2 using ..\output\Table_1_panelB.tex, tex(frag) append label  nocons addtext(HS digit product category, 6, Country-product fixed effects, Yes, Product-year fixed effects, Yes) addstat(Dependent variable mean, `m') dec(0) rdec(2) ctitle ("Capital") 

reghdfe B1_hs6 commodity_exports   if type_of_good=="consumption", absorb(ch6 yh6)  cluster(cy)
sum B1_hs6 if e(sample)==1
loc m = r(mean)
outreg2 using ..\output\Table_1_panelB.tex , tex(frag) append label nocons addtext(HS digit product category, 6, Country-product fixed effects, Yes, Product-year fixed effects, Yes) addstat(Dependent variable mean, `m' ) dec(0) rdec(2)  ctitle ("Consumption") 


reghdfe B1_hs6 compriceindexfixw  if type_of_good=="primary", absorb(ch6 yh6) cluster(cy)
sum B1_hs6 if e(sample)==1
loc m = r(mean)
outreg2 using ..\output\Table_1_panelB.tex, tex(frag) append label nocons addtext(HS digit product category, 6, Country-product fixed effects, Yes, Product-year fixed effects, Yes) addstat(Dependent variable mean, `m' ) dec(0) rdec(2) ctitle ("Primary")   

reghdfe B1_hs6 compriceindexfixw  if type_of_good=="capital", absorb(ch6 yh6) cluster(cy)
sum B1_hs6 if e(sample)==1
loc m = r(mean)
outreg2 using ..\output\Table_1_panelB.tex, tex(frag) append label  nocons addtext(HS digit product category, 6, Country-product fixed effects, Yes, Product-year fixed effects, Yes) addstat(Dependent variable mean, `m') dec(0) rdec(2) ctitle ("Capital") 

reghdfe B1_hs6 compriceindexfixw  if type_of_good=="consumption", absorb(ch6 yh6)  cluster(cy)
sum B1_hs6 if e(sample)==1
loc m = r(mean)
outreg2 using ..\output\Table_1_panelB.tex , tex(frag) append label nocons addtext(HS digit product category, 6, Country-product fixed effects, Yes, Product-year fixed effects, Yes) addstat(Dependent variable mean, `m' ) dec(0) rdec(2) ctitle ("Consumption") 

}


********************************************************************************
********************************************************************************
//Table 2
loc run = 1
if `run' == 1{
//Alternative measures

********************************************************************************
********************************************************************************
//Panel A
reghdfe B7i commodity_exports , absorb(ch6 yh6) cluster(cy)
sum B7i if e(sample)==1
loc m = r(mean)
outreg2 using ..\output\Table_2A.tex, tex(frag) replace label nocons addtext(HS digit product category, 6, Country-product fixed effects, Yes, Product-year fixed effects, Yes) addstat(Dependent variable mean, `m') dec(3) rdec(2)  

reghdfe B7iinew commodity_exports , absorb(ch6 yh6) cluster(cy)
sum B7iinew if e(sample)==1
loc m = r(mean)
outreg2 using ..\output\Table_2A.tex, tex(frag) append label  nocons addtext(HS digit product category, 6, Country-product fixed effects, Yes, Product-year fixed effects, Yes) addstat(Dependent variable mean, `m') dec(3) rdec(2)  

reghdfe ln_A1 commodity_exports , absorb(ch6 yh6) cluster(cy)
sum ln_A1 if e(sample)==1
loc m = r(mean)
outreg2 using ..\output\Table_2A.tex, tex(frag) append label  nocons addtext(HS digit product category, 6, Country-product fixed effects, Yes, Product-year fixed effects, Yes) addstat(Dependent variable mean, `m') dec(3) rdec(2) 

reghdfe ln_G1 commodity_exports , absorb(ch6 yh6) cluster(cy)
sum ln_G1 if e(sample)==1
loc m = r(mean)
outreg2 using ..\output\Table_2A.tex, tex(frag) append label  nocons addtext(HS digit product category, 6, Country-product fixed effects, Yes, Product-year fixed effects, Yes) addstat(Dependent variable mean, `m')  dec(3) rdec(2) 

reghdfe H1 commodity_exports , absorb(ch6 yh6) cluster(cy)
sum H1 if e(sample)==1
loc m = r(mean)
outreg2 using ..\output\Table_2A.tex, tex(frag) append label  nocons addtext(HS digit product category, 6, Country-product fixed effects, Yes, Product-year fixed effects, Yes) addstat(Dependent variable mean, `m')   dec(3) rdec(2) 

reghdfe ln_G2 commodity_exports , absorb(ch6 yh6) cluster(cy)
sum ln_G2 if e(sample)==1
loc m = r(mean)
outreg2 using ..\output\Table_2A.tex, tex(frag) append label  nocons addtext(HS digit product category, 6, Country-product fixed effects, Yes, Product-year fixed effects, Yes) addstat(Dependent variable mean, `m')   dec(3) rdec(2) 


}

********************************************************************************
********************************************************************************
//Panel B
loc run =1
if `run' == 1{
//Alternative measures

********************************************************************************
********************************************************************************

reghdfe B7i compriceindexfixw , absorb(ch6 yh6) cluster(cy)
sum B7i if e(sample)==1
loc m = r(mean)
outreg2 using ..\output\Table_2B.tex, tex(frag) replace label nocons addtext(HS digit product category, 6, Country-product fixed effects, Yes, Product-year fixed effects, Yes) addstat(Dependent variable mean, `m') dec(3) rdec(2)  

reghdfe B7iinew compriceindexfixw , absorb(ch6 yh6) cluster(cy)
sum B7iinew if e(sample)==1
loc m = r(mean)
outreg2 using ..\output\Table_2B.tex, tex(frag) append label  nocons addtext(HS digit product category, 6, Country-product fixed effects, Yes, Product-year fixed effects, Yes) addstat(Dependent variable mean, `m') dec(3) rdec(2)  

reghdfe ln_A1 compriceindexfixw , absorb(ch6 yh6) cluster(cy)
sum ln_A1 if e(sample)==1
loc m = r(mean)
outreg2 using ..\output\Table_2B.tex, tex(frag) append label  nocons addtext(HS digit product category, 6, Country-product fixed effects, Yes, Product-year fixed effects, Yes) addstat(Dependent variable mean, `m') dec(3) rdec(2) 

reghdfe ln_G1 compriceindexfixw , absorb(ch6 yh6) cluster(cy)
sum ln_G1 if e(sample)==1
loc m = r(mean)
outreg2 using ..\output\Table_2B.tex, tex(frag) append label  nocons addtext(HS digit product category, 6, Country-product fixed effects, Yes, Product-year fixed effects, Yes) addstat(Dependent variable mean, `m')  dec(3) rdec(2) 

reghdfe H1 compriceindexfixw , absorb(ch6 yh6) cluster(cy)
sum H1 if e(sample)==1
loc m = r(mean)
outreg2 using ..\output\Table_2B.tex, tex(frag) append label  nocons addtext(HS digit product category, 6, Country-product fixed effects, Yes, Product-year fixed effects, Yes) addstat(Dependent variable mean, `m')   dec(3) rdec(2) 

reghdfe ln_G2 compriceindexfixw , absorb(ch6 yh6) cluster(cy)
sum ln_G2 if e(sample)==1
loc m = r(mean)
outreg2 using ..\output\Table_2B.tex, tex(frag) append label  nocons addtext(HS digit product category, 6, Country-product fixed effects, Yes, Product-year fixed effects, Yes) addstat(Dependent variable mean, `m')   dec(3) rdec(2) 

}

